package com.chenfan.magic.enums;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * @author liuming
 * @date 2021-03-12 16:40
 */
public enum StatusEnum {
    /**
     * 状态信息
     */
    ISV_OFFLINE(0, "ISV_OFFLINE"),
    ISV_GRAY_NOT_ALLOW(1, "ISV_GRAY_NOT_ALLOW"),
    ISV_DEV(3, "ISV_DEV"),
    ISV_EXC(4, "ISV_EXC"),
    ISV_FORBIDDEN(5, "ISV_FORBIDDEN"),
    ISV_IN_CHECK(6, "ISV_IN_CHECK"),
    ISV_CHECK_FALSE(7, "ISV_CHECK_FALSE"),
    ;
    private Integer code;

    private String desc;

    StatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static StatusEnum getByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        Optional<StatusEnum> optional = Arrays.stream(StatusEnum.values()).filter(x -> code.equals(x.getCode())).findAny();
        if (!optional.isPresent()) {
            return null;
        }
        return optional.get();
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
